package com.financing.platform.web.api;

import java.util.Collections;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.financing.platform.common.Pager;
import com.financing.platform.common.ResultCode;
import com.financing.platform.common.ResultMap;
import com.financing.platform.common.ResultMap.STATUS;
import com.financing.platform.dto.ActivitiesWinListDTO;
import com.financing.platform.service.IActivitiesWinListService;

@Controller("activitiesWinListActionApi")
@RequestMapping("/api/activities")
@Scope("prototype")
public class ActivitiesWinListAction extends BaseAction{
	
	@Autowired
	private IActivitiesWinListService activitiesWinListServiceImpl;
	
	
	@SuppressWarnings("unchecked")
	@RequestMapping("/queryActivitiesWinList.shtml")
	@ResponseBody
	public ResultMap queryActivitiesWinList(HttpServletRequest request,
			HttpServletResponse response,ActivitiesWinListDTO activitiesWinListDTO,Pager pager) {
		try{
			log.info("Begin queryActivitiesWinList list!");
			
			activitiesWinListDTO.setBegin(pager.getStartIndex());
			activitiesWinListDTO.setPageSize(pager.getPageSize());
			int count = activitiesWinListServiceImpl.queryActivitiesWinListCount(activitiesWinListDTO);
			
			pager.setTotalCount(count);
			
			List<ActivitiesWinListDTO> list;
			if(count>0){
				list = activitiesWinListServiceImpl.getActivitiesWinListList(activitiesWinListDTO);
			}else{
				list = Collections.EMPTY_LIST;
			}
			resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			resultMap.setAttribute("list",list);
			resultMap.setAttribute("pager",pager);
			
			log.info("End queryActivitiesWinList list!");
		}catch(Exception e){
			log.error("queryActivitiesWinList error !",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
			return resultMap;
	}
}
